package com.ellricky.baselib.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.andr.common.util.ScreenUtil;

public class WorkListItemDecoration extends RecyclerView.ItemDecoration {


    private Context mContext;
    private int space;

    public WorkListItemDecoration(Context context, int space) {
        this.space = (int) ScreenUtil.dpUnit(context, space);
        mContext = context;
    }


    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);

        int pos = parent.getChildAdapterPosition(view);
        int column = pos % 3 + 1;
        if (column == 1){
            outRect.left = (int) ScreenUtil.dpUnit(mContext, 35);
        }else{
            outRect.left = (column - 1) * space / 3;
        }

        outRect.top = 0;
        outRect.bottom = 0;
        //右侧为(总条目数-当前条目数)/总条目数*divider宽度
        outRect.right = 0;

    }
}

